package com.project.server.broadroom;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.broadroom.TBroadroom;
import com.project.server.service.broadroom.ITBroadroomBookService;
import com.project.server.service.broadroom.ITBroadroomService;
import com.project.server.service.companies.ITCompanyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * 会议室信息Controller
 *
 * @author project
 * @date 2021-06-22
 */
@RestController
@RequestMapping("/server/broadroom")
public class TBroadroomController extends BaseController {

    @Resource
    private ITBroadroomService tBroadroomService;

    @Resource
    private ITBroadroomBookService tBroadroomBookService;

    @Resource
    private ITCompanyService companyService;

    /**
     * 查询会议室信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:broadroom:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBroadroom tBroadroom) throws ParseException {
        startPage();
        List<TBroadroom> list = tBroadroomService.selectTBroadroomList(tBroadroom);
        return getDataTable(list);

    }

    /**
     * 导出会议室信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:broadroom:export')")
    @Log(title = "会议室信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TBroadroom tBroadroom) throws ParseException {
        List<TBroadroom> list = tBroadroomService.selectTBroadroomList(tBroadroom);
        ExcelUtil<TBroadroom> util = new ExcelUtil<TBroadroom>(TBroadroom.class);
        return util.exportExcel(list, "会议室列表");
    }

    /**
     * 获取会议室信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:broadroom:query')")
    @GetMapping(value = "/{broadroomId}")
    public AjaxResult getInfo(@PathVariable("broadroomId") Long broadroomId) {
        AjaxResult ajax = AjaxResult.success();
        ajax.put(AjaxResult.DATA_TAG, tBroadroomService.selectTBroadroomById(broadroomId));
        ajax.put("comps", companyService.selectTCompanyAll());
        return ajax;
    }

    /**
     * 新增会议室信息
     */
    @PreAuthorize("@ss.hasPermi('server:broadroom:add')")
    @Log(title = "会议室信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TBroadroom tBroadroom) {
        return AjaxResult.success(tBroadroomService.insertTBroadroom(tBroadroom));
    }

    /**
     * 修改会议室信息
     */
    @PreAuthorize("@ss.hasPermi('server:broadroom:edit')")
    @Log(title = "会议室信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TBroadroom tBroadroom) {
        return toAjax(tBroadroomService.updateTBroadroom(tBroadroom));
    }

    /**
     * 删除会议室信息
     */
    @PreAuthorize("@ss.hasPermi('server:broadroom:remove')")
    @Log(title = "会议室信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{broadroomIds}")
    public AjaxResult remove(@PathVariable Long[] broadroomIds) {
        return toAjax(tBroadroomService.deleteTBroadroomByIds(broadroomIds));
    }
}
